﻿using System;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace WebPattern.Core.Validators
{
    public class NotNullOrNotWhiteSpaceValidator : Validator
    {
        protected override string DefaultMessageTemplate 
        {  
            get { return base.MessageTemplate; }
        }
        
        public NotNullOrNotWhiteSpaceValidator(string messageTemplate) : base(messageTemplate,"")
        {
        }

        public override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            if (string.IsNullOrWhiteSpace(objectToValidate.ToString())) validationResults.AddResult(new ValidationResult("String value is null or white space", typeof(string), "", "", null));
        }
    }
}
